Skip to content

Sort published samples explicitly instead of relying on readdir order - #28

Merged
leggetter merged 1 commit into
mainfrom
fix/deterministic-sample-order
Aug 11, 2026
Merged

leggetter merged 1 commit into
mainfrom
fix/deterministic-sample-order

Conversation

@leggetter

Copy link
Copy Markdown
Collaborator

compile.ts never sorted anything. Providers, versions and topics were emitted in fs.readdir order, which is filesystem-dependent — APFS returns entries sorted, ext4 with dir_index returns them in hash order. The published files look alphabetical today only because they were last built on a Mac.

There's no CI in this repo and public/ is gitignored, so the order consumers receive currently depends on whose machine ran yarn compile. Providers, versions and topics are now sorted explicitly.

Topics sort by topic, not by filename

Those are different strings: orders.create.json publishes the topic orders/create, and the topic is what consumers see. They happen to sort identically today because . and / are adjacent in ASCII with nothing between them — a coincidence, not a reason to sort the wrong key. Collecting the parsed topics first and sorting by the published key removes the dependency on that.

Also: one write per version instead of one per topic

The writeFile sat inside the topic loop, so each version file was rewritten once per sample, each time with a progressively more complete object. shopify/2026-07 was written 217 times per build. It's now written once, after the loop.

Testing

yarn compile output is byte-identical to the previous build across all 112 providers — same content, same key order, verified for providers.json and a version file. Two consecutive runs now produce identical bytes (md5 match), which wasn't previously guaranteed across machines.

Pairs with a Console change that orders the provider list by inbound webhook volume and then alphabetically; this PR is what makes the alphabetical half of that dependable.

🤖 Generated with Claude Code

https://claude.ai/code/session_019pce9oHWGjdwHsJNya1ovP

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webhook-samples Ready Ready Preview Aug 11, 2026 9:18am

Request Review

Nothing in compile.ts sorted. Providers, versions and topics were
emitted in `fs.readdir` order, which is filesystem-dependent: APFS
returns entries sorted, ext4 with dir_index returns them in hash order.
The published files look alphabetical today only because they were last
built on a Mac. There is no CI in this repo and `public/` is gitignored,
so the order consumers receive depends on whose machine ran the build.

Providers, versions and topics are now sorted explicitly.

Topics are sorted by the topic they publish, not by filename. Those are
different strings — `orders.create.json` publishes `orders/create` — and
the topic is what consumers see. They happen to sort identically today
because `.` and `/` are adjacent in ASCII with nothing between them, but
that is a coincidence, not a reason to sort the wrong key.

Also writes each version file once rather than once per topic. The write
was inside the topic loop, so shopify/2026-07 was written 217 times per
build, each time with a progressively more complete object.

Output is byte-identical to the previous build across all 112 providers,
and two consecutive runs now produce identical bytes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019pce9oHWGjdwHsJNya1ovP
@leggetter
leggetter force-pushed the fix/deterministic-sample-order branch from f084bc3 to 4019a43 Compare August 11, 2026 09:18
@leggetter
leggetter merged commit 8ffd4cb into main Aug 11, 2026
3 checks passed
@leggetter
leggetter deleted the fix/deterministic-sample-order branch August 11, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant